<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>

<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" >
                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">城市列表</li>
                            <li onclick="go('add_city')">添加城市</li>
                        </ul>
                        <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">

                            <div class="layui-tab-item layui-show">

                                <div>

                                   <!-- &lt;!&ndash;搜索&ndash;&gt;
                                    <div class="layui-inline" style="float: right">
                                        <form class="layui-form" action="">
                                            <div class="layui-form-item" style="margin-bottom: 0px">

                                                <div class="layui-inline" style="margin-right: 0px">
                                                    <div class="layui-input-inline" style="width: 200px;">
                                                        <input type="text" name="keyword" autocomplete="off"
                                                               placeholder="请输入标题"
                                                               class="layui-input">
                                                    </div>
                                                </div>

                                                <div class="layui-inline" style="margin-right: 0px">
                                                    <div class="layui-btn-group layui-inline" style="margin: 0px">
                                                        &lt;!&ndash;此重置 仅仅是个跳转链接&ndash;&gt;
                                                        <button  onclick="go('index')" class="layui-btn layui-btn-primary">重置</button>
                                                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">
                                                            <i class="layui-icon">&#xe615;</i>查找
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>-->
                                </div>

                                <div class="layadmin-trailer ">

                                    <table class="layui-table" lay-skin="line">

                                        <thead>
                                        <tr>
                                            <th style="width: 5%"></th>
                                            <th style="width: 30%">城市ID</th>
                                            <th style="width: 30%">城市名称</th>
                                            <th style="width: 35%">展示状态</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="(item,index) in items" :data_id="item.aid">
                                            <td style="width: 20px;text-align: center">
                                                <input type="checkbox" class="vue_index" name="aid" :value="item.id"
                                                       style="zoom: 150%">
                                            </td>
                                            <td>{{item.city_id}}</td>
                                            <td>{{item.city_name}}</td>
                                            <td  v-if="item.is_show == 0">
                                                <button id="show" onclick="set_show(this)"
                                                        :data_id="item.id" :data_index="index"
                                                        class="layui-btn layui-btn-xs"
                                                        style="background-color: #c2c2c2">展示
                                                </button>
                                            </td>
                                            <td  v-if="item.is_show == 1">
                                                <button id="show" onclick="unset_show(this)"
                                                        :data_id="item.id" :data_index="index"
                                                        class="layui-btn layui-btn-xs">展示
                                                </button>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <div id="demo7"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    //vue对象
    var app = new Vue({
        el: '#app',
        data: {
            check: [],
            curr: 1,//当前页
            limit: 10,//当前须展示信息条数
            items: [],
        }
    });

    //初始数据
    function init() {
        layer.load(2);
        $.get('/admin/city/index', {page: app.curr, limit: app.limit},
            function (res) {
                layer.closeAll();
                app.items = res.data;
            }
        );
    }

    //按需引入layui模块
    layui.use(['laypage', 'layer','table','element'], function () {
        var laypage = layui.laypage
            , layer = layui.layer;
        var table = layui.table;
        var elemnet = layui.element;
        //完整功能
        laypage.render({
            elem: 'demo7'
            , count: "{$count}"
            , limits: [10, 20]
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            , jump: function (obj) {
                app.curr = obj.curr;
                app.limit = obj.limit;
                init();
            }
        });

    });

    //Demo
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            // layer.msg(JSON.stringify(data.field));
            layer.load(2);
            $.get('/admin/article/article_search', data.field, function (res) {

                    layui.use(['laypage'], function () {
                        var laypage = layui.laypage;
                        //完整功能
                        laypage.render({
                            elem: 'demo7'
                            , count: res.total
                            , limits: [10, 20]
                            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                            , jump: function (obj) {
                                console.log(obj)
                                app.curr = obj.curr;
                                app.limit = obj.limit;
                                layer.load(2);
                                $.get('/admin/article/article_search', {
                                        page: app.curr,
                                        limit: app.limit,
                                        keyword: data.field.keyword,
                                        fenlei:data.field.fenlei
                                    },
                                    function (res) {
                                        layer.closeAll();
                                        app.items = res.data;
                                    }
                                );
                            }
                        });
                    });
                }
            );
            return false;
        });
    });

    //点击编辑弹出弹框
    function edit(that) {

        var data_id = $(that).attr('data_id');
        layer.open({

            type: 2,
            title: '编辑',
            shadeClose: true,
            shade: 0.01,
            area: ['80%', '90%'],
            content: "{:url('edit_article')}?id=" + data_id //iframe的url

        });


    }
    //展示
    function set_show(obj) {
        var index = layer.confirm('确认展示？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            var data_id = $(obj).attr('data_id');
            $.post('{:url("set_show")}',{is_show:1,data_id:data_id},
                function (res) {
                    if (res.code == 1) {
                        layer.close(index);
                        layer.msg(res.msg, {icon: 1});
                        init();
                    }
                    else{
                        layer.close(index);
                    }
                });
        }, function () {
            layer.close(index);
        });


    }
    //取消展示
    function unset_show(obj) {
        console.log("取消推荐tuijian");
        var index = layer.confirm('确认取消展示？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            var data_id = $(obj).attr('data_id');
            $.post('{:url("set_show")}',{is_show:0,data_id:data_id},
                function (res) {
                    if (res.code == 1) {
                        layer.close(index);
                        layer.msg(res.msg, {icon: 1});
                        init();
                    }
                    else{
                        layer.close(index);
                    }
                });
        }, function () {
            layer.close(index);
        });


    }

</script>


</body>
</html>




